package com.tiamosu.navigation.ext

import androidx.fragment.app.Fragment
import androidx.lifecycle.LifecycleOwner

/**
 * @author tiamosu
 * @date 2021/9/1.
 */
/**
 * 获取LifecycleOwner
 */
val LifecycleOwner.getLifecycleOwner: LifecycleOwner
    get() {
        return when (this) {
            is Fragment -> {
                try {
                    this.viewLifecycleOwner
                } catch (e: IllegalStateException) {
                    this
                }
            }
            else -> this
        }
    }